<script>
import axios from 'axios'
axios.defaults.baseURL = 'http://127.0.0.1:3001'

export default {
    data() {
        return {
            editblog: {
            }
        }
    },
    created() {
       this.fetch()
    },
    methods: {
        saveArticle() {
            console.log(this.editblog)
            axios.put('/blog/' + this.$route.params.id, this.editblog).then(res => {
                console.log(res.data)
                this.$message({
                    type: 'success',
                    message: '文章保存成功'
                })
                this.$router.push('/blog/list')
            })
        },
    fetch() {
        axios.get(`blogs/${this.$route.params.id}`).then(res => {
            this.editblog = res.data
        })
    }
}

}

</script>
<template>
    <div>
        <el-form ref="form" :model="editblog" label-width="80px" @submit.prevent="saveArticle()"> 
            <el-form-item label="文章标题">
                <el-input v-model="editblog.title"></el-input>
            </el-form-item>
            <el-form-item label="文章内容">
                <el-input type="textarea" v-model="editblog.body" rows="20"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" native-type="submit">保存</el-button>
            </el-form-item>
            <el-form-item>
                <el-button @click="this.$router.go(-1)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<style></style>